/*
 *  Copyright 2013 National Institute of Advanced Industrial Science and Technology
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.sss.mapreduce;

/**
 * Key format.
 */
public enum KeyFormat {
  /** Order of processing format */
  ORDER(0),
  /** Thread priority format */
  THREAD(1),
  /** User key priority format */
  USERKEY(2);

  private static final String formatCharTable = "0123456789ABCDEF";
  private byte byteValue;
  private char charValue;

  private KeyFormat(int n) {
    if ((n & ~0x0F) != 0) {
      throw new IllegalArgumentException(
          "Invalid key format: n. " +
          "Key format must be less than 16");
    }
    this.byteValue = (byte)n;
    this.charValue = formatCharTable.charAt(n);
  }

  /**
   * Get 'byte' expression.
   *
   * @return 'byte' expression of this key format.
   */
  public byte getByte() { return byteValue; }

  /**
   * Get 'charactor' expression.
   *
   * @return 'charactor' expresion of this key format.
   */
  public char getChar() { return charValue; }

  /**
   * Default key format.
   */
  public static KeyFormat DEFAULT = KeyFormat.THREAD;
}
